# vPresent is an immersive presentation creation and display application.
# Copyright (C) 2007 by Infiscape Corporation
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

# Maestro is Copyright (C) 2006-2007 by Infiscape
#
# Original Author: Aron Bierbaum
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

import types

class _const:
   class ConstError(TypeError): pass
   def __setattr__(self,name,value):
      if self.__dict__.has_key(name):
         raise self.ConstError, "Can't rebind const %s" % name

      self.__dict__[name] = value

const = _const()

const.OS_ERROR   = 0
const.OS_UNKNOWN = 1
const.OS_LINUX   = 2
const.OS_WIN95   = 3
const.OS_WINNT   = 4
const.OS_MACOS   = 5
const.OS_MACOSX  = 6
const.OS_HPUX    = 7
const.OS_AIX     = 8
const.OS_SOLARIS = 9
const.OS_FREEBSD = 10

const.OS_NAME_MAP = {
   const.OS_ERROR   : ['Error'],
   const.OS_UNKNOWN : ['Unknown'],
   const.OS_LINUX   : ['Linux', 'UNIX'],
   const.OS_WIN95   : ['Windows 95'],
   const.OS_WINNT   : ['Windows'],
   const.OS_MACOS   : ['Mac OS Classic'],
   const.OS_MACOSX  : ['Mac OS X', 'UNIX'],
   const.OS_HPUX    : ['HP-UX', 'UNIX'],
   const.OS_AIX     : ['AIX', 'UNIX'],
   const.OS_SOLARIS : ['Solaris', 'UNIX'],
}

CONTINUE = 0
STOP = 1
SKIP = 2

def traverse(obj, enter, exit):
   if type(obj) in [types.ListType, types.TupleType]:
      return traverse_list(obj, enter, exit)

   result = enter(obj)
   if SKIP == result:
      result = CONTINUE
   elif CONTINUE == result:
      if obj.acceptsChildren():
         result = traverse_list(obj._children, enter, exit)

   return exit(obj, result)

def traverse_list(nodes, enter, exit):
   result = CONTINUE
   for node in nodes:
      result = traverse(node, enter, exit)
      if STOP == result:
         break
   return result
